package com.wanghengzhi.girlfriend.rbac.core;

import lombok.Data;

/**
 * 用于api之间调用，返回结果，如果是失败，可以包含错误信息以及错误数据。
 * @author wanghengzhi
 * @since 2021.6.17
 */
public final class Call {

    private boolean ok;

    private String message;

    private Object data;

    private Call() {

    }

    public boolean ok() {
        return ok;
    }

    public String message() {
        return message;
    }

    public Object data() {
        return data;
    }

    public Call ok(boolean ok) {
        this.ok = ok;
        return this;
    }

    public Call message(String message) {
        this.message = message;
        return this;
    }

    public Call data(Object data) {
        this.data = data;
        return this;
    }

    public static Call get(){
        return new Call();
    }

    /**
     * 由于Call没有标准的get、set
     * 需要转换为RT对象，
     * @return
     */
    public RT response(){
        RT rt = new RT();
        rt.setOk(this.ok);
        rt.setMessage(this.message);
        rt.setData(this.data);
        return rt;
    }

    @Override
    public String toString() {
        return "Call{" +
                "ok=" + ok +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    @SuppressWarnings("unchecked")
    @Data
    public class RT{
        private boolean ok;

        private String message;

        private Object data;

    }
}
